<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:shiro="http://shiro.apache.org/tags">

<ui:composition template="/views/templates/main.xhtml">
	<ui:define name="body">
		<style>
.navigation .rf-tab-hdr-brd,.navigation .rf-tab {
	display: none;
}
</style>
	<h:form>
		<shiro:guest>
		<a4j:outputPanel id="panel" layout="block">
                <a4j:repeat value="#{rSSBetFirBean.lastResults}" var="feed" rows="20"
                    id="repeat">
                      <h:panelGrid columns="1">
         	             <rich:extendedDataTable value="#{feed.entries}"
				            var="mess" id="table" frozenColumns="1"
				            style="height:300px; width:720px;" selectionMode="none" >
				            <f:facet name="header">
				                <h:outputText value="#{feed.title}" />
				            </f:facet>
				            <rich:column width="480px">
				                <f:facet name="header">
				                    <h:outputText value="Mercado" />
				                </f:facet>
				                <h:outputText value="#{mess.title}" />
				            </rich:column>
				            <rich:column  width="240px">
				                <f:facet name="header">
				                    <h:outputText value="Ganadores" />
				                </f:facet>
				                <h:outputText value="#{mess.description}" />
				            </rich:column>
					        </rich:extendedDataTable>
				        </h:panelGrid>	
	            </a4j:repeat>
            </a4j:outputPanel>
            <a4j:outputPanel layout="block">
                <rich:dataScroller for="repeat" render="panel" />
            </a4j:outputPanel>
           </shiro:guest> 
        	
        <shiro:hasRole name="usuario">
			<h:panelGrid columnClasses="acent">
				<rich:dataScroller for="table" maxPages="5" />
			        <rich:dataTable value="#{userAccountBean.lastUserBets}" var="bet"
			            id="table" rows="10">
			            <rich:column>
			                <f:facet name="header">
			                    <h:outputText value="Evento" />
			                </f:facet>
			                <h:outputText value="#{bet.eventTypeName}/#{bet.eventName}//#{bet.marketName}" />
			            </rich:column>
			            <rich:column>
			                <f:facet name="header">
			                    <h:outputText value="Apuesta" />
			                </f:facet>
			                <h:outputText value="#{bet.marketResultName}" />
			            </rich:column>
			            <rich:column>
			                <f:facet name="header">
			                    <h:outputText value="Monto" />
			                </f:facet>
			                <h:outputText value="#{bet.amountFormatted}" />
			            </rich:column>
			            <rich:column>
			                <f:facet name="header">
			                    <h:outputText value="Fecha Apuesta" />
			                </f:facet>
			                <h:outputText value="#{bet.dateFormatted}" />
			            </rich:column>
			            <rich:column>
			                <f:facet name="header">
			                    <h:outputText value="combinada" />
			                </f:facet>
			                <h:outputText value="#{bet.compositeId}" />
			            </rich:column>
			            
			            <rich:column>
			                <f:facet name="header">
			                    <h:outputText value="Ganancia" />
			                </f:facet>
			                <h:outputText value="#{bet.resultFormatted}" />
			            </rich:column>
			        </rich:dataTable>
			    <rich:dataScroller for="table" maxPages="5" />
			  </h:panelGrid>
            </shiro:hasRole>
            <shiro:hasRole name="administrador">
            	 <rich:dataGrid value="#{userAccountBean.marketsWithPendingResults}"
					var="entry" columns="4" elements="9" width="600px" border="0">
	                <rich:panel bodyClass="pbody">
	                    <f:facet name="header">
	                        <h:outputText value="#{entry.date}"></h:outputText>
						</f:facet>
						
						<rich:dataTable value="#{entry.value}" var="mark">
				            <f:facet name="header">
				                <rich:columnGroup>
				                    <rich:column colspan="3">
				                        <h:outputText value="" />
				                    </rich:column>
				                </rich:columnGroup>
				            </f:facet>
				            <rich:column colspan="6">
				                <rich:collapsibleSubTableToggler for="sbtbl" />
				                <h:outputText value="#{mark.name}" />
				            </rich:column>
				            <rich:collapsibleSubTable value="#{mark.children}" var="result" id="sbtbl" expandMode="client" expanded="#{false}">
				                <rich:column>
				                    <h:outputText value="#{result.name}" />
				                </rich:column>
				                <rich:column>
				                    <h:outputText value="#{result.amount}" />
				                </rich:column>
				                <rich:column>
				                	<h:commandButton  disabled="#{false}"  image="/images/win-icon.png" action="#{userAccountBean.setWinner}">
				                		<f:param name="res" value="#{result.id}"/> 
				                		<f:param name="markId" value="#{mark.id}"/>
				                	</h:commandButton>
					            </rich:column>
				            </rich:collapsibleSubTable>
				        </rich:dataTable>
	                </rich:panel>
					<f:facet name="footer">
	                    <rich:dataScroller />
	                </f:facet>
	            </rich:dataGrid>
            </shiro:hasRole>
        </h:form>
   </ui:define>
</ui:composition>

</html>